<template>
  <div class="index">
    <div class="search">
      <input type="text" placeholder="输入商家丶商品名称" @click="$router.push('/mysearch')">
    </div>

    <div class="banner">
      <van-swipe class="my-swipe" loop :autoplay="2000" indicator-color="white">
        <van-swipe-item v-for='(item,index) in bannerData' :key="index">
          <img :src="item.bannerUrl" alt="">
        </van-swipe-item>
      </van-swipe>
    </div>

    <div class="likeyou">
      <div class="like">
        <h3>猜你喜欢</h3>
      </div>
    </div>

    <div class="sort">
      <span v-for='(item,index) in sortArr' :key="index" @click='tabber(index)' :class="{active:currentsortArr == index}">
        {{item}}
      </span>
    </div>

    <div class="best-seller">
      <span v-for='(item,index) in bestsellerData' :key="index">
        {{item}}
      </span>
    </div>

    <div class="shopping">
      <div class="main" v-for='(item,index) in mainData' :key="index" @click='router_xiangqing(item)'>
        <div class="count">
          <div class="count-left">
            <div class="img">
              <img :src="item.picUrl" alt="">
            </div>
          </div>

          <div class="count-right">
            <div class="title">
              <h3>{{item.name}}</h3>
            </div>
            <div class="xing-yueshou"><span style="color:red">⭐ 4.3</span>&nbsp;&nbsp;<span>{{item.monthSalesTip}}</span></div>
            <div class="qisong">
              <span>{{item.minPriceTip}}</span>
              <span>远距离{{item.shippingFeeTip}}</span>
              <span>{{item.deliveryTimeTip}}</span>
              <span>{{item.distance}}</span>
              <span>&nbsp;{{item.wmPoiScore}}</span>
            </div>

            <div class="evaluate">
              <div class="evn">“扬州炒饭真好吃”</div>
              <div class="evn">海淀区北京菜畅销第2</div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { banner_list } from "../../axios/api";
import { shop_list } from "../../axios/api";
import { Toast } from 'vant';

export default {

  data() {
    return {
      bannerData: {},
      sortArr: ['综合排序', '距离最近', '销量最高', '品质联盟'],
      currentsortArr: 0,
      bestsellerData: ['年货节热卖', '津贴联盟', '满减优惠', '品质联盟'],
      mainData: []
    }
  },

  methods: {
    tabber(index) {
      this.currentsortArr = index;
      if (index == 1) {
        this.mainData.sort((a, b) => {
          return a.wmPoiScore - b.wmPoiScore
        })
      }
      if (index == 2) {
        this.mainData.sort((a, b) => {
          return b.wmPoiScore - a.wmPoiScore
        })
      }
      if (index == 3) {
        this.mainData.sort((a, b) => {
          return a.wmPoiScore - b.wmPoiScore
        })
      }
    },
    router_xiangqing(item) {
      this.$router.push('/myparticulars/' + item.mtWmPoiId)

    }
  },

  mounted() {
    banner_list().then(
      response => {
        if (response.data.code == 200) {
          this.bannerData = response.data.list;
          Toast.clear();
          //   console.log(response.data);
        }
      }
    ),

      shop_list().then(
        response => {
          this.mainData = response.data.list
          // console.log(response.data);
        }
      )
  },
}
</script>

<style lang='scss' scoped>
.shopping {
  width: 100%;
  height: 100%;
  //   background-color: aqua;
  margin-top: 15px;
  margin-bottom: 50px;

  .main {
    margin-bottom: 10px;
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    .count {
      width: 94%;
      height: 140px;
      //   background-color: pink;
      display: flex;
      align-items: center;
      justify-content: space-between;
      .count-left {
        width: 30%;
        height: 100%;
        // background-color: red;
        display: flex;
        justify-content: center;
        align-items: center;
        .img {
          width: 80%;
          height: 80%;
          img {
            width: 100%;
            height: 100%;
          }
        }
      }
      .count-right {
        flex: 1;
        height: 100%;
        // background-color: rgba(255, 166, 0, 0.173);
        .xing-yueshou {
          margin: 8px;
          span {
            color: gray;
            font-size: 14px;
          }
        }
        .qisong {
          width: 100%;
          height: 24px;
          //   background-color: rgba(255, 0, 0, 0.185);
          display: flex;
          justify-content: space-around;
          align-items: center;
          span {
            color: gray;
            font-size: 14px;
          }
        }
        .evaluate {
          width: 100%;
          height: 30px;
          margin-top: 6px;
          //   background-color: rgba(255, 0, 0, 0.207);
          display: flex;
          align-items: center;
          .evn {
            width: 120px;
            margin-left: 10px;
            height: 20px;
            background-color: #ffe6b5;
            border-radius: 10px;
            color: #ff5000;
            font-size: 12px;
            text-align: center;
            line-height: 20px;
          }
        }
      }
    }
  }
}
.best-seller {
  width: 100%;
  height: 30px;
  display: flex;
  justify-content: space-around;
  align-items: center;
  margin-top: 5px;
  span {
    width: 23%;
    height: 24px;
    background-color: rgba(128, 128, 128, 0.289);
    border-radius: 10px;
    text-align: center;
    line-height: 24px;
    color: rgba(0, 0, 0, 0.749);
  }
}
.sort {
  width: 100%;
  height: 30px;
  //   background-color: aqua;
  margin-top: 5px;
  display: flex;
  justify-content: space-around;
  align-items: center;
  span {
    color: black;
    font-weight: 600;
  }
  .active {
    color: red;
  }
}

.likeyou {
  margin-top: 20px;

  .like {
    width: 100%;
    height: 30px;
    // background-color: aqua;

    h3 {
      padding-left: 15px;
      color: rgba(0, 0, 0, 0.782);
    }
  }
}

.banner {
  width: 100%;
  height: 100px;
  //   background-color: aqua;
  border-radius: 20px;
  margin-top: 20px;
  display: flex;
  justify-content: center;
  align-items: center;

  .my-swipe {
    border-radius: 20px;
    width: 94%;
    height: 100%;
    color: #fff;
    font-size: 20px;
    line-height: 150px;
    text-align: center;
    background-color: #39a9ed;

    img {
      width: 100%;
      height: 100%;
    }
  }
}
.search {
  width: 100%;
  height: 70px;
  background-color: #00f2ff;
  display: flex;
  justify-content: center;
  align-items: center;
  position: sticky;
  top: 0;
  z-index: 999;
  input {
    width: 90%;
    height: 30px;
    border: 1px solid gray;
    border-radius: 30px;
    text-align: center;
    line-height: 30px;
    outline: none;
    color: gray;
    font-size: 14px;
  }
}
</style>